﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Aga.Controls.Tree;

namespace LogoScriptIDE
{
	/// <summary>
    /// 变量表，用来存储整个watches的信息
	/// </summary>

	public class varTableModel : ITreeModel
	{
		/// <summary>
        /// 添加一个观察变量
		/// </summary>
		/// <param name="s">变量名</param>
        public void addVar(string s)
        {
            var q = new Varforwatch() { Name = s };
            this.Root.Children.Add(q);
        }

		/// <summary>
        ///  删除一个观察变量
		/// </summary>
		/// <param name="index">变量位置</param>
        public void deleteVar(int index)
        {
            if (index >= 0)
                this.Root.Children.RemoveAt( index );
        }

		/// <summary>
        /// 整个varTableModel是一个树状结构，root表示树根
		/// </summary>
        public Varforwatch Root { get; private set; }

        /// <summary>
        /// 构造函数
        /// </summary>
		public varTableModel()
		{
            Root = new Varforwatch();
		}

        /// <summary>
        /// 获得节点的子节点
        /// </summary>
        /// <param name="parent">父节点</param>
        /// <returns>子节点遍历器</returns>
		public System.Collections.IEnumerable GetChildren(object parent)
		{
			if (parent == null)
				parent = Root;
            return (parent as Varforwatch).Children;
		}

        /// <summary>
        /// 判断某节点是否有子节点
        /// </summary>
        /// <param name="parent">待判断的节点</param>
        /// <returns>若存在子节点则返回真，反之返回假</returns>
		public bool HasChildren(object parent)
		{
            return (parent as Varforwatch).Children.Count > 0;
		}
	}
}
